// 合并两个排序的链表
// 输入两个递增排序的链表，合并两个链表并使得新链表中的结点仍按递增排序的。
#include <iostream>
#include "LinkedList.h"
using namespace std;

ListNode * MergeSortedList(ListNode * pListHead1, ListNode * pListHead2)
{
    if (pListHead1 == NULL)
        return pListHead2;
    if (pListHead2 == NULL)
        return pListHead1;
    ListNode * pMergedList = NULL;
    if (pListHead1->m_nValue < pListHead2->m_nValue)
    {
        pMergedList = pListHead1;
        pMergedList->m_pNext = MergeSortedList(pListHead1->m_pNext, pListHead2);
    }
    else
    {
        pMergedList = pListHead2;
        pMergedList->m_pNext = MergeSortedList(pListHead1, pListHead2->m_pNext);
    }
    return pMergedList;
}

int main(int argc, char * argv[])
{
    ListNode * pListHead1 = NULL;
    ListNode * pListHead2 = NULL;

    for(int i = 0; i < 10; ++ i)
    {
    //    AddToTail(&pListHead1, 2 * i);
    //    AddToTail(&pListHead2, 3 * i);
    }
    PrintList(pListHead1);
    PrintList(pListHead2);

    ListNode * pMergedList = MergeSortedList(pListHead1, pListHead2);
    PrintList(pMergedList);
    
    DestoryList(pListHead1);
    DestoryList(pListHead2);
    
}   
